package com.burgeon.backend.EnterpriseWeChat.rest.VipInfo;
/**
 * 添加采购退货单的头和明细（上海）
 */

import com.burgeon.backend.EnterpriseWeChat.entity.VipSkinInfo;
import com.burgeon.backend.Rest.base.RESTBase;
import org.apache.http.util.TextUtils;
import org.json.JSONArray;
import org.springframework.util.MultiValueMap;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

public class saveUserSkinInfo extends RESTBase {

    private String ip;
    private String account;
    private String password;

    public saveUserSkinInfo(String ip, String account, String password) {
        this.ip = ip;
        this.account = account;
        this.password = password;
    }

    /**
     * 发送并接收字符创
     */

    public String getData(VipSkinInfo vipSkinInfo,String id) throws Exception {
        String url = "http://" + ip + "/servlets/binserv/Rest";
        String str = RESULT(Data(vipSkinInfo,id), url);
        System.err.println(str);
        String code = new JSONArray(str).getJSONObject(0).getString("code");
        String message = new JSONArray(str).getJSONObject(0).getString("message");


        if (!"0".equals(code)) {
            throw new Exception("保存色型质"+message);
        }
        String objectid = new JSONArray(str).getJSONObject(0).getString("objectid");
        return objectid;

    }

    private MultiValueMap Data(VipSkinInfo vipSkinInfo,String id) {
      //  System.err.println("'"+retail.getC_STORE_ID()+"'");
//        params["command"] = "ProcessOrder"
//        params["id"] = "C_VIP"
        HashMap params = new HashMap();
        HashMap masterObjs = new HashMap(); //头表记录对象，采购退货单
        masterObjs.put("table", "C_VIP");
        masterObjs.put("ak", id);

        if (!TextUtils.isEmpty(vipSkinInfo.getColor())&& !vipSkinInfo.getColor().equals("null")) {
            masterObjs.put("APP_VIP_COLOR_ID__NAME", vipSkinInfo.getColor());
        }
        if (!TextUtils.isEmpty(vipSkinInfo.getType())&&!vipSkinInfo.getColor().equals("null")) {
            masterObjs.put("APP_VIP_TYPE_ID__NAME", vipSkinInfo.getType());
        }
        if (!TextUtils.isEmpty(vipSkinInfo.getQuality())&&!vipSkinInfo.getColor().equals("null")) {
            masterObjs.put("APP_VIP_QUALITY_ID__NAME", vipSkinInfo.getQuality());
        }
        if (!TextUtils.isEmpty(vipSkinInfo.getShape())&&!vipSkinInfo.getColor().equals("null")) {
            masterObjs.put("APP_VIP_SHAPE_ID__NAME", vipSkinInfo.getShape());

        }
        if (!TextUtils.isEmpty(vipSkinInfo.getSummarize())&&!vipSkinInfo.getColor().equals("null")) {//总结
            masterObjs.put("APP_CTQ_DESCRIPTION", vipSkinInfo.getSummarize());

        }
//            if (!TextUtils.isEmpty(vipModel.desc)) {
//                masterObjs["DESCRIPTION2"] = vipModel.desc

        params.put("masterobj", masterObjs);
//        params.put("detailobjs", detailobjs);


//        params.put("submit", "true");//是否提交
        System.err.println(params);
        return DATA("ProcessOrder", params, account, password);
    }

    public static void main(String[] args) {
        saveUserSkinInfo g = new saveUserSkinInfo("59.110.28.94:90", "nea@burgeon.com.cn", "burgeon55321");
        try {
//            RETAIL retail = new RETAIL();
//            retail.setC_STORE_ID("唐山爱琴海购物公园专卖店");
//            retail.setBILLDATE("20200616");
//            retail.setRETAILBILLTYPE("正常零售");
//            retail.setRECEIVEDESP("null");
            VipSkinInfo vipSkinInfo = new VipSkinInfo();
            vipSkinInfo.setColor("皮肤暗黄");
            vipSkinInfo.setType("");
            vipSkinInfo.setQuality("");
            vipSkinInfo.setShape("");
            vipSkinInfo.setSummarize("");
            g.getData(vipSkinInfo,"13643111382");
        } catch (Exception e) {
            e.printStackTrace();
            System.err.println(e.getMessage());
        }
    }
}
